package myListener;

import java.awt.FlowLayout;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JList;

import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;

import myWindows.JMyVentana;

public class JTestMultiple extends JMyVentana {
    public JTestMultiple() {
        InitGUI();
    }
    
    private final String nombreColores[] = {
            "Negro", "Azul", "Cyan", "Gris Oscuro", "Gris", "Verde", "Gris Claro",
            "Magenta", "Naranja", "Rosa", "Rojo", "Blanco", "Amarillo"};
    
    private JList lista1, lista2;
    private JButton boton;
    
    public void InitGUI(){
        this.getContentPane().setLayout(new FlowLayout());
        this.setSize(350, 200);
        
        //Creamos la primera Lista
        lista1 = new JList(nombreColores);
        lista1.setVisibleRowCount(6);
        lista1.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        add(new JScrollPane(lista1));
        
        //Creamos el boton
        boton = new JButton("Copiar >>");
        add(boton);
        
        boton.addActionListener(new ActionListener(){
                    public void actionPerformed(ActionEvent e) {
                        lista2.setListData(lista1.getSelectedValues());

                    }
                });
        
        //Creamos la segunda lista
         lista2 = new JList();
         lista2.setVisibleRowCount(6);
         lista2.setFixedCellWidth(100);
         lista2.setFixedCellHeight(18);
         lista2.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
         add(new JScrollPane(lista2));
    }
    public static void main(String[] args) {
        JTestMultiple obj = new JTestMultiple();
        obj.setVisible(true);
    }
}
